//
//  DKScrollView.m
//  HUB
//
//  Created by 许建勇 on 15/7/18.
//  Copyright (c) 2015年 许建勇. All rights reserved.
//

#import "DKScrollView.h"

@interface DKScrollView()<UIGestureRecognizerDelegate>
/**记录上一次frame的形状*/
@property CGRect previousFrame;
@end

@implementation DKScrollView

#pragma mark - 初始化操作
-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if(self)
    {
        [self custonInit];
    }
    return self;
}


//自定义的初始化内容
-(void)custonInit
{
    
    //数值初始化
    _previousFrame=CGRectZero;
    
    UITapGestureRecognizer* singleTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(receiveTouch)];
    singleTap.delegate=self;
    [self addGestureRecognizer:singleTap];
    [self initParameter];
    [self initUI];
}





#pragma mark - 重写父类的方法
-(void)layoutSubviews
{
    [super layoutSubviews];
    if(CGRectEqualToRect(_previousFrame, self.frame))
    {//形状相同，则不通知刷新布局
        
    }
    else
    {//形状不同，通知刷新布局，且记录新布局
        _previousFrame=self.frame;
        [self refreshLayout:_previousFrame];
    }
}



#pragma mark - gestureDelegate
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]])
    {
        if(gestureRecognizer.view==touch.view)
        {
            return YES;
        }
        else
        {
            return NO;
        }
    }
    
    return YES;
}



#pragma mark - getter
-(NSMutableDictionary*)info
{
    if(_info==nil)
    {
        _info=[[NSMutableDictionary alloc] init];
    }
    return _info;
}



#pragma mark - 私有方法
/**点击事件*/
-(void)receiveTouch
{
    /*NSArray* subViews=self.subviews;
    for(int i=0;i<subViews.count;i++)
    {
        UIView* view=subViews[i];
        [view resignFirstResponder];
    }*/
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
}




#pragma mark - 扩展方法
/**传参初始化*/
-(instancetype)initWithInfo:(NSMutableDictionary*)info
{
    self=[super init];
    if(self)
    {
        _info=info;
        [self custonInit];
    }
    return self;
}

/**初始化UI界面*/
-(void)initUI
{
    
}

/**初始化数值参数*/
-(void)initParameter
{
    
}

/**页面布局调整*/
-(void)refreshLayout:(CGRect)frame
{
    
}

@end
